home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue43 / alfresco / Project1.dpr < prev    next >
Encoding:
Text File  |  1999-01-17  |  2.1 KB  |  89 lines

  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Windows,
  8.   AASkpLst in 'AASkpLst.pas';
  9.  
  10. const
  11.   ItemCount = 1000;
  12.  
  13. function CompareItems(aItem1, aItem2 : pointer) : integer; far;
  14. var
  15.   I1 : longint absolute aItem1;
  16.   I2 : longint absolute aItem2;
  17. begin
  18.   Result := I1 - I2;
  19. end;
  20.  
  21. var
  22.   SkipList : TaaSkipList;
  23.   i        : integer;
  24.   Prev     : integer;
  25. begin
  26.   Randomize;
  27.   try
  28.     writeln('SKIP LIST TEST');
  29.     SkipList := TaaSkipList.Create(CompareItems);
  30.     try
  31.       {add 10 items in reverse order}
  32.       writeln('Adding ', ItemCount, ' items');
  33.       for i := 1 to ItemCount do
  34.         SkipList.Insert(pointer(i));
  35.       {check order of the skip list}
  36.       writeln('Checking order of items in skip list');
  37.       SkipList.MoveBeforeFirst;
  38.       SkipList.MoveNext;
  39.       Prev := 0;
  40.       while not SkipList.IsAfterLast do begin
  41.         i := integer(SkipList.Examine);
  42.         if (i-Prev <> 1) then
  43.           writeln('error');
  44.         Prev := i;
  45.         SkipList.MoveNext;
  46.       end;
  47.       SkipList.MoveAfterLast;
  48.       SkipList.MovePrior;
  49.       Prev := integer(SkipList.Examine);
  50.       SkipList.MovePrior;
  51.       while not SkipList.IsBeforeFirst do begin
  52.         i := integer(SkipList.Examine);
  53.         if (Prev-i <> 1) then
  54.           writeln('error');
  55.         Prev := i;
  56.         SkipList.MovePrior;
  57.       end;
  58.       {search for each item}
  59.       writeln('Searching for all items...');
  60.       for i := 1 to ItemCount do
  61.         if not SkipList.Search(pointer(i)) then
  62.           writeln('***Cannot find ', i);
  63.       writeln('Done searching');
  64.       writeln('MaxLevel ', SkipList.MaxLevel);
  65.       readln;
  66.       SkipList.Print;
  67.       readln;
  68.       {delete bunch of items}
  69.       writeln('Deleting some items...');
  70.       SkipList.MoveBeforeFirst;
  71.       SkipList.MoveNext;
  72.       for i := 1 to ItemCount do begin
  73.         if (i mod 13) = 0 then
  74.           SkipList.Delete
  75.         else
  76.           SkipList.MoveNext;
  77.       end;
  78.       writeln('Done deleting');
  79.       SkipList.Print;
  80.     finally
  81.       SkipList.Free;
  82.     end;
  83.   except
  84.     on E : Exception do
  85.       writeln(E.Message);
  86.   end;
  87.   readln;
  88. end.
  89.